const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const miniCssExtractPlugin = require('mini-css-extract-plugin')
module.exports = {
  entry: path.resolve(__dirname, '../src/main.ts'),
  output: {
    filename: 'js/leis[contenthash:8].js',
    path: path.resolve(__dirname, '../dist'),
    clean: true,
    // 配置环境
    environment: {
      arrowFunction: false
    }
  },
  resolve: {
    extensions: ['.js', '.json', '.ts'],
    alias: {
      '@': path.resolve(__dirname, '../src')
    }
  },
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: [
          // babel-loader的配置搬到.babelrc文件中
          'babel-loader',
          'ts-loader'
        ],
        exclude: /node_modules/,
      },
      {
        test: /(\.scss$)|(\.sass$)/,
        use: [
          // 这里可能需要验证，之后改用style-loader
          miniCssExtractPlugin.loader,
          'css-loader',
          // 具体配置搬到postcss.config.js
          'postcss-loader',
          'sass-loader'
        ]
      },
      {
        test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
        use: {
          loader: 'url-loader',
          options: {
            limit: 10000,
            esModule: false,
            name: 'imgs/[name]_[hash:7].[ext]'
          }
        },
      },
    ]
  },
  plugins: [
    new miniCssExtractPlugin({
      chunkFilename: '[id].css',
      filename: 'css/leis.css'
    }),
    new HtmlWebpackPlugin({
      template: path.resolve(__dirname, '../index.html')
    })
  ],
}
